package com.itcat.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.SmsHomeBrand;
import com.itcat.mysql.pojo.SmsHomeRecommendSubject;
import com.itcat.service.SmsHomeRecommendSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/recommendSubject")
public class SmsHomeRecommendSubjectController {

    @Autowired
    private SmsHomeRecommendSubjectService smsHomeRecommendSubjectService;

    /**
     * 分页查询推荐品牌
     * @param pageNum
     * @param pageSize
     * @param subjectName
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam Integer pageNum,
                             @RequestParam Integer pageSize,
                             String subjectName,
                             Integer recommendStatus){

        Page<SmsHomeRecommendSubject> subjectPage = smsHomeRecommendSubjectService.list(pageNum, pageSize, subjectName, recommendStatus);
        CommonPage<SmsHomeRecommendSubject> restPage = CommonPage.restPage(subjectPage);
        return CommonResult.success(restPage);
    }

    /**
     * 添加首页推荐品牌
     * @param subjects
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsHomeRecommendSubject> subjects){
        smsHomeRecommendSubjectService.create(subjects);
        return CommonResult.success();
    }

    /**
     * 修改专题推荐排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public CommonResult updateSort(@PathVariable Integer id,
                                   @RequestParam Integer sort) {
        smsHomeRecommendSubjectService.updateSort(id, sort);
        return CommonResult.success();
    }

    /**
     * 批量修改推荐状态
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public CommonResult updateRecommendStatus(@RequestParam List<Integer> ids,
                                              @RequestParam  Integer recommendStatus) {
        smsHomeRecommendSubjectService.updateRecommendStatus(ids, recommendStatus);
        return CommonResult.success();
    }

    /**
     * 批量删除专题推荐
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List<Integer> ids) {
        smsHomeRecommendSubjectService.delete(ids);
        return CommonResult.success();
    }
}
